﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;



namespace lab3
{
    /// <summary>
    /// class Gradebook
    /// </summary>
    /// <author>sdavis31 2/4/2008</author>
    class Gradebook
    {
        // create StudentList
        StudentList data;

        public StudentList Data
        {
            get { return data; }
            set { data = value; }
        }

        /// <summary>
        /// Reading in the XML file.
        /// </summary>
        /// <author>sdavis31 2/4/2008</author>
        public void ReadXML()
        {
            // read in the XML file for students
            XmlSerializer deserial = new XmlSerializer(typeof(StudentList));
            string filename = "students.xml";
            TextReader read = new StreamReader(filename);
            data = (StudentList)deserial.Deserialize(read);
            read.Close();
        }

        /// <summary>
        /// Showing the Grade Report from the XML file.
        /// </summary>
        /// <author>sdavis31 2/4/2008</author>
        /// <returns>string for the Report - to be used by Main program to output to console</returns>
        public string ShowReport()
        {
            // return string
            string myReturn;

            // retrieve Report using ToString
            myReturn = data.ToString();

            // make sure something is returned, or giving appropriate message
            if (myReturn == "")
            {
                myReturn = "No data was returned!";
            }

            // return Report
            return myReturn;
        }
    }
}
